
//
//  xmkcup.m
//  PASystem
//
//  Created by michael on 16/8/25.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "xmkcup.h"

@implementation xmkcup
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    
   
          }
    return self;
}
- (void)setField:(NSString *)field{

_field = field;
[self request];
}
- (void)request{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':kcxxMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_field];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
        _dic = dict;
       [self initview];

    } failure:^(NSError *error) {
        
    }];
}
- (void)initview{

_tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableview.frame = CGRectMake(0, 0, KScreenWidth-20, (KScreenHeight-64-46-80)/3-40);
_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"考察内容:";
     CGFloat titleSize = [OAToolBox sizebyText:[NSString stringWithFormat:@"%@",_dic[@"CONTENTS"]] font:12 minsWidth:120];

      if (titleSize<30) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}

    
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
 label2.textAlignment = NSTextAlignmentRight;
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"CONTENTS"]];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==1) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"考察地点:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
 
 
//     label2.text = _dic[@"cause"];
label2.textAlignment = NSTextAlignmentRight;
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"ADDRESS"]];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }


 else{
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"出发时间:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];

 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,cell.height)];
     //时间
  NSString *string = _dic[@"TIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];

    label2.text = selfYear;

     label2.font = [UIFont systemFontOfSize:12];
     label2.textAlignment = NSTextAlignmentRight;
          label2.numberOfLines = 0;
    [cell.contentView addSubview:label2];
    return cell;

 
 
 
 
 }
 
 
 }

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 30;
if (indexPath.row == 0){
 CGFloat titleSize = [OAToolBox sizebyText:[NSString stringWithFormat:@"%@",_dic[@"CONTENTS"]] font:12 minsWidth:120];


//CGFloat titleSize = 180;
if (titleSize<30) {
    return 30;
}else{
return titleSize;

}
}
else{

return H;
}

}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

@end
